<?php

/**
 * This is the model class for table "echange".
 *
 * The followings are the available columns in table 'echange':
 * @property integer $id
 * @property integer $idoffre
 * @property integer $nb
 * @property integer $valeur
 * @property string $status
 * @property string $date_echange
 * @property string $date_debut
 * @property string $date_fin
 * @property string $date_saisie
 * @property integer $idseliste_saisie
 * @property string $comm_dem
 * @property string $comm_off
 * *
 * The followings are the available model relations:
 * @property Offre $idoffre0
 */
class Echange extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'echange';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('idoffre, idseliste_saisie', 'required'),
			array('idoffre, idseliste_saisie, nb, valeur', 'numerical', 'integerOnly'=>true),
			array('status', 'length', 'max'=>1),
			array('date_echange, date_debut, date_fin, date_saisie', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, idoffre, nb, valeur, status, date_echange, date_debut, date_fin, date_saisie', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'idoffre0' => array(self::BELONGS_TO, 'Offre', 'idoffre'),
			'idselisteSaisie' => array(self::BELONGS_TO, 'Seliste', 'idseliste_saisie'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'idoffre' => 'Idoffre',
			'nb' => 'Nb',
			'valeur' => 'Valeur',
			'status' => 'Status',
			'date_echange' => 'Date Echange',
			'date_debut' => 'Date Debut',
			'date_fin' => 'Date Fin',
			'date_saisie' => 'Date Saisie',
			'idseliste_saisie' => 'Séliste',
			'comm_dem' => 'Commentaire demandeur',
			'comm_off' => 'Commentaire offrant',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('idoffre',$this->idoffre);
		$criteria->compare('nb',$this->nb);
		$criteria->compare('valeur',$this->valeur);
		$criteria->compare('status',$this->status,true);
		$criteria->compare('date_echange',$this->date_echange,true);
		$criteria->compare('date_debut',$this->date_debut,true);
		$criteria->compare('date_fin',$this->date_fin,true);
		$criteria->compare('date_saisie',$this->date_saisie,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
			'pagination'=>array(
					'pageSize'=>40,
			),
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Echange the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
